package com.lemon.smartsafetynew.ui.fragment.record;

import android.os.Bundle;
import android.util.Log;

import com.lemon.android.http.LemonRequestParams;
import com.lemon.smartsafety.app.RefreshType;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafetynew.entity.electrical.ElectricalCompanyVo;
import com.lemon.smartsafetynew.ui.activity.electrical.ElectricalSafePointListActivity;
import com.lemon.smartsafetynew.ui.fragment.base.BasePullToRefreshFragment;
import com.lemon.smartsafety.utils.app.UIHelper;
import com.lemon.smartsafetynew.entity.me.MeCompanyVo;
import com.lemon.smartsafetynew.entity.record.SwitchBoxVo;
import com.lemon.smartsafetynew.net.services.RecordServices;
import com.lemon.smartsafetynew.ui.adapter.record.SwitchBoxAdapter;
import com.lemon.smartsafetynew.util.constants.KeyConstants;
import com.lemon.smartsafetynew.util.user.AccountUtil;

import java.util.List;

import kale.adapter.LemonRcvAdapter;

/**
 * 配电箱信息
 * Created by Andrew on 2018/3/30.
 */

public class SwitchBoxFragment extends BasePullToRefreshFragment<SwitchBoxVo, List<SwitchBoxVo>>
        implements RecyclerTClickListener<SwitchBoxVo> {


    private static MeCompanyVo companyVo;

    @Override
    protected void getBaseArguments() {
        super.getBaseArguments();

        Bundle bundle = getArguments();
        if (bundle != null) {
            if (bundle.containsKey(KeyConstants.KEY_COMPANY_VO)) {
                companyVo = (MeCompanyVo) bundle.getSerializable(KeyConstants.KEY_COMPANY_VO);
            }
        }
    }

    public static SwitchBoxFragment newInstance(MeCompanyVo companyVo) {

        Bundle args = new Bundle();
        args.putSerializable(KeyConstants.KEY_COMPANY_VO, companyVo);
        SwitchBoxFragment fragment = new SwitchBoxFragment();
        fragment.setArguments(args);
        return fragment;
    }


    @Override
    public void onPullRefresh() {

        LemonRequestParams params = new LemonRequestParams("");

        params.put("companyId", companyVo.getCompany_id());
        params.put("user_id", AccountUtil.getUserID());
        params.put("pageNum", currentPage);
        params.put("pageSize", pageSize);
        RecordServices.init().getSwitchBoxInfoList(RefreshType.REFRESH, params);

    }

    @Override
    public void onLoadMore() {

        LemonRequestParams params = new LemonRequestParams("");

        params.put("companyId", companyVo.getCompany_id());
        params.put("user_id", AccountUtil.getUserID());
        params.put("pageNum", currentPage);
        params.put("pageSize", pageSize);
        RecordServices.init().getSwitchBoxInfoList(RefreshType.LOAD_MORE, params);

    }

    @Override
    public void onItemClick(SwitchBoxVo data, int position) {
        ElectricalCompanyVo itemVo = new ElectricalCompanyVo();
        itemVo.setCompanyId(data.getCompanyId());
        itemVo.setCompanyName(data.getCompanyName());
        itemVo.setBoxId(data.getId());
        Bundle bundle = new Bundle();
        bundle.putSerializable(KeyConstants.KEY_ELECTRICAL_COMPANY_INFO, itemVo);
        UIHelper.showActivity(getmContext(), bundle, ElectricalSafePointListActivity.class);
    }

    @Override
    public boolean goRefreshOnCreate() {
        return true;
    }

    @Override
    public LemonRcvAdapter<SwitchBoxVo> getLemonAdapter() {
        return new SwitchBoxAdapter(mDataList,this);
    }

    @Override
    public String getHttpTag() {
        return KeyConstants.URL_COMPANY_INFO_SWITCH_BOX_LIST;
    }
}
